<?php
defined('IN_PHPCMS') or exit('No permission resources.');
$db = '';
$db = pc_base::load_model('book_model');
$db_category = pc_base::load_model('category_model');

$page = isset($_GET['page'])?intval($_GET['page']):1;
$catid = isset($_GET['catid'])?intval($_GET['catid']):0;
get_book($catid,$page,12);

//获取瀑布流图书信息
function get_book($catid=0,$page=1,$pagesize=12)
{
    global $db,$db_category;
    $pagenow = ($page-1)<0?(0*$pagesize):($page-1)*$pagesize; //当前页

    $arr_category = $db_category->get_one('catid='.$catid);
    $where = '';
    if($arr_category['child'])
    {
        $catids_str = $arr_category['arrchildid'];
        $pos = strpos($catids_str,',')+1;
        $catids_str = substr($catids_str, $pos);
        $where = 'p.catid IN ('.$catids_str.')';
    }
    else
    {
        $where = 'p.catid = '.$catid;
    }
    $query = 'SELECT p.id,p.title,p.thumb,p.url,d.info FROM `'.$db->db_tablepre.'book` p INNER JOIN `'.$db->db_tablepre.'book_data` d ON p.id = d.id WHERE '.$where.'  LIMIT '.$pagenow.','.$pagesize;

    $res = $db->query($query);
    $row = $db->fetch_array();
	$count = count($row);

    $str_html  = '';
    if($count>0)
    {
        foreach($row as $key => $val)
        {
            $str_html .= '<div class="grid">';
            $str_html .= '<div class="imgholder"><a href="'.$row[$key][url].'" target="_blank"><img class="lazy" src="'.SKIN_PATH.'images/pixel.gif" data-original="'.thumb($row[$key][thumb],216,0).'" width="215" /></a></div>';
            $str_html .= '<strong><a href="'.$row[$key][url].'" target="_blank">'.$row[$key][title].'</a></strong>';
            $str_html .= '<p class="info">'.str_cut(strip_tags($row[$key][info]),100).'</p>';
            $str_html .= '<div class="meta"><a href="'.$row[$key][url].'" target="_blank">点击查看&gt;&gt;</a></div>';
            $str_html .= '</div>';
        }
        echo $str_html;
    }

}
?>